//
//  LeftViewController.m
//  DeepBreathing
//
//  Created by rimi on 15/12/19.
//  Copyright © 2015年 rimi. All rights reserved.
//

#import "LeftViewController.h"
#import "NetworkManger+User.h"
#import "UserModel.h"
#import "LoginViewController.h"
#import "ControllerManager.h"
#import "BasicMessengeViewController.h"



@interface LeftViewController()

@property(nonatomic,strong)UIImageView *backView;
@property(nonatomic,strong)UILabel *welcomeLabel;
@property(nonatomic,strong)UILabel *phoneLabel;





@end


@implementation LeftViewController
-(void)viewDidLoad{
    
    
    [super viewDidLoad];
    [self.view addSubview:self.backView];
    [self.view addSubview:self.welcomeLabel];
    self.view.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
    NSArray *nameArray = @[@"首页",@"个人信息",@"修改密码",@"评价一下",@"关于我们"];
    
    for (int  i  = 0; i < 5; i++) {
        UIButton *button  = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(0,CGRectGetMaxY(self.backView.frame) +  35 + i * 50 + 10, 300, 50);
        [button setImage:[UIImage imageNamed:nameArray[i]] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor colorWithRed:1.0 green:0.5889 blue:0.207 alpha:1.0] forState:UIControlStateNormal];

        [button setTitle:nameArray[i] forState:UIControlStateNormal];
        button.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 244);
        
        button.titleEdgeInsets = UIEdgeInsetsMake(0, 50, 0, 130);
        
        
       
        button.tag = 200 + i;
        button.titleLabel.font = [UIFont systemFontOfSize:20];
        [button addTarget:self action:@selector(buttonTaped:) forControlEvents:UIControlEventTouchUpInside];

               [self.view addSubview:button];
    }
    
    _phoneLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.welcomeLabel.frame)+ 5, 155, 20)];
    _phoneLabel.font = [UIFont systemFontOfSize:20];
    _phoneLabel.textAlignment = NSTextAlignmentRight;
    _phoneLabel.textColor = [UIColor whiteColor];
    _phoneLabel.text = [UserModel defaultUser].phoneNumber;

    
    
    [self.view addSubview:_phoneLabel];
    
    UIButton *exitbutton = [UIButton buttonWithType:UIButtonTypeCustom];
    exitbutton.frame = CGRectMake(0,CGRectGetMaxY(self.view.frame) - 55, 300, 40);
    [exitbutton setImage:[UIImage imageNamed:@"退出登录"] forState:UIControlStateNormal];
    [exitbutton setTitleColor:[UIColor colorWithRed:1.0 green:0.5889 blue:0.207 alpha:1.0] forState:UIControlStateNormal];
    
    [exitbutton setTitle:@"退出登录" forState:UIControlStateNormal];
    exitbutton.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 244);
    
    exitbutton.titleEdgeInsets = UIEdgeInsetsMake(0, 50, 0, 130);
    
    
    exitbutton.titleLabel.font = [UIFont systemFontOfSize:20];
    [exitbutton addTarget:self action:@selector(buttonExit:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:exitbutton];

    
    
}
#pragma mark -- getter
-(UIImageView *)backView{
    
    
    if (!_backView) {
        _backView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 310, 185)];
        _backView.image = [UIImage imageNamed:@"侧栏背景"];
    }
    return _backView;
}
-(UILabel *)welcomeLabel{
    if (!_welcomeLabel) {
        _welcomeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 100, 90, 35)];
        _welcomeLabel.text = @"欢迎您";
        _welcomeLabel.font = [UIFont systemFontOfSize:20];
        _welcomeLabel.textAlignment = NSTextAlignmentRight;
        _welcomeLabel.textColor = [UIColor whiteColor];
    }
    
    
    
    
    return _welcomeLabel;
}
-(void)buttonTaped:(UIButton *)sender{
    
    NSInteger i = sender.tag  - 200;
    switch (i) {
        case 0:
            [self dedeede];
            break;
        case 1:
            [self openBasicMesenge];
            break;

        case 2:
            [self dedeede];
            break;

        case 3:
            [self dedeede];
            break;

        case 4:
            [self dedeede];
            break;

            
        default:
            break;
    }
    
    
}

-(void)openBasicMesenge{
    NSLog(@"das");
    
    BasicMessengeViewController *BASVC = [[BasicMessengeViewController alloc]init];
    
    [self.navigationController pushViewController:BASVC animated:YES];
    
    
}
-(void)dedeede{
    
}

-(void)buttonExit:(UIButton *)sender
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"是否退出登录" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        [[ControllerManager sharedManager].drawerVC closeLeftDrawer];
        
        LoginViewController *lvv = [[LoginViewController alloc]init];
        
        UINavigationController *navc = [[UINavigationController alloc]initWithRootViewController:lvv];
        
        [self presentViewController:navc animated:NO completion:^{
            
            self.view.alpha = 1;
            
        }];

        
    }];
    
    [alertController addAction:action];
    [alertController addAction:action2];
    [self presentViewController:alertController animated:YES completion:nil];


}
@end
